/////////////////////////////////////////////////////////////////////////////
// 2023 -
//open source under Apache License Version 2.0
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <iostream>
#include <kmhdfs/client/preconditions.h>

using namespace Hdfs;
using namespace Hdfs::Internal;

namespace Hdfs {
namespace Internal {

Preconditions::Preconditions() {
}

/**
 * Ensures the truth of an expression involving the state of the calling
 * instance, but not involving any parameters to the calling method.
 *
 * @param expression a boolean expression
 */
void Preconditions::checkState(bool expression) {
    if (!expression){
        THROW(InvalidParameter, "illegal state exception.");
    }   
}

/**
 * Ensures the truth of an expression involving one or more parameters to the
 * calling method.
 *
 * @param expression a boolean expression
 * @throws IllegalArgumentException if {@code expression} is false
 */
void Preconditions::checkArgument(bool expression) {
    if (!expression) {
        THROW(InvalidParameter, "invalid parameter exception.");
    }
}

void Preconditions::checkArgument(bool expression, string errorMessage) {
    if (!expression){
        THROW(InvalidParameter, errorMessage.c_str());
    }
}

void Preconditions::checkNotNull(void* reference) {
    if (reference == nullptr) {
        THROW(InvalidParameter, "null pointer exception.");
    }
}

}
}
